package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname PermissionController
 * @Description TODO
 * @Date 2020/10/9 10:15
 * @Created by Administrator
 */
@RestController
@RequestMapping("/permission")
@Slf4j
public class PermissionController {

    @Reference
    private PermissionService permissionService;
    /**
     * 查询出所有权限
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findAll")
    public Result findAll(QueryPageBean queryPageBean){

      PageResult pageResult =  permissionService.findAll(queryPageBean);
      return new Result(true,"分页查询成功",pageResult);
    }
    /**
     * 添加权限
     */
    @RequestMapping("/permissionAdd")
    public Result permissionAdd(@RequestBody Permission permission){

        permissionService.permissionAdd(permission);
        return new Result(true, "添加权限成功");
    }
    /**
     * 回显权限
     * @param
     * @return
     */
    @RequestMapping("/permissionUpdate")
    public Result permissionUpdate(Integer id){
     Permission permission =  permissionService.permissionUpdate(id);
      return new Result(true,"回显数据成功",permission);
    }
    /**
     * 更新权限
     */
    @RequestMapping("/permissionEdit")
    public Result permissionEdit(@RequestBody Permission permission){

        permissionService.permissionEdit(permission);
         return new Result(true,"更新权限成功");
    }
    /**
     * 删除权限
     */
    @RequestMapping("/permissionDelete")
    public Result permissionDelete(Integer id){
        permissionService.permissionDelete(id);
        return new Result(true,"删除权限成功");
    }
}
